<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
<HTML>
<HEAD>
<LINK REL=STYLESHEET TYPE="text/css" HREF="../../stylesheet.css" TITLE="Style">
<META NAME="GENERATOR" CONTENT="Java2HTML Version 1.5">
<TITLE>czestmyr.jjsched.Console (Java2HTML)</TITLE>
</HEAD>
<BODY><TABLE id="Header" border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td colspan="2" width="33%">&nbsp;</td>
<td align="center" colspan="2" width="33%">
<font size="4">Console.java</font>
</td>
<td align="right" colspan="2" width="33%">&nbsp;</td>
</tr>
</TABLE>
<pre ID="Classes">
<A NAME="1"></A><FONT ID="MultiLineComment">/*  This file is a part of JJSched source code
<A NAME="2"></A>    JJSched - Java Jabber Scheduler - a simple Jabber scheduling application
<A NAME="3"></A>    Copyright (C) 2008 Cestmir "CZestmyr" Houska
<A NAME="4"></A>
<A NAME="5"></A>    This program is free software: you can redistribute it and/or modify
<A NAME="6"></A>    it under the terms of the GNU General Public License as published by
<A NAME="7"></A>    the Free Software Foundation, either version 3 of the License, or
<A NAME="8"></A>    (at your option) any later version.
<A NAME="9"></A>
<A NAME="10"></A>    This program is distributed in the hope that it will be useful,
<A NAME="11"></A>    but WITHOUT ANY WARRANTY; without even the implied warranty of
<A NAME="12"></A>    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
<A NAME="13"></A>    GNU General Public License for more details.
<A NAME="14"></A>
<A NAME="15"></A>    You should have received a copy of the GNU General Public License
<A NAME="16"></A>    along with this program.  If not, see &lt;http://www.gnu.org/licenses/&gt; */</FONT>
<A NAME="17"></A>
<A NAME="18"></A><FONT ID="Package">package</FONT> czestmyr.jjsched;
<A NAME="19"></A>
<A NAME="20"></A><FONT ID="Import">import</FONT> java.io.*;
<A NAME="21"></A><FONT ID="Import">import</FONT> java.nio.channels.*;
<A NAME="22"></A><FONT ID="Import">import</FONT> java.util.*;
<A NAME="23"></A>
<A NAME="24"></A><FONT ID="FormalComment">/**
<A NAME="25"></A> * Handles master console input
<A NAME="26"></A> */</FONT>
<A NAME="27"></A><FONT ID="Public">public</FONT> <FONT ID="Class">class</FONT> Console <FONT ID="Extends">extends</FONT> Thread {
<A NAME="28"></A>    Console (<A HREF="../../czestmyr/jjsched/CommandParser.java.html">CommandParser</A> p, <A HREF="../../czestmyr/jjsched/ActionExecutor.java.html">ActionExecutor</A> ae, <A HREF="../../czestmyr/jjsched/Macros.java.html">Macros</A> m) {
<A NAME="29"></A>        theExecutor = ae;
<A NAME="30"></A>        theParser = p;
<A NAME="31"></A>        theMacros = m;
<A NAME="32"></A>
<A NAME="33"></A>        reader = <FONT ID="New">new</FONT> BufferedReader(
<A NAME="34"></A>                 <FONT ID="New">new</FONT> InputStreamReader(
<A NAME="35"></A>                 Channels.newInputStream(
<A NAME="36"></A>                 (<FONT ID="New">new</FONT> FileInputStream(FileDescriptor.in)).getChannel())));
<A NAME="37"></A>        doContinue = <FONT ID="True">true</FONT>;
<A NAME="38"></A>
<A NAME="39"></A>        <FONT ID="SingleLineComment">//Set the thread name for easier identification
<A NAME="40"></A></FONT>        setName(<FONT ID="StringLiteral">"JJSched console thread"</FONT>);
<A NAME="41"></A>        <FONT ID="SingleLineComment">//Lower the priority of this thread
<A NAME="42"></A></FONT>        setPriority(<FONT ID="IntegerLiteral">4</FONT>);
<A NAME="43"></A>    }
<A NAME="44"></A>
<A NAME="45"></A>    <FONT ID="FormalComment">/**
<A NAME="46"></A>     * Processes the console input by reading System.in
<A NAME="47"></A>     */</FONT>
<A NAME="48"></A>    <FONT ID="Public">public</FONT> <FONT ID="Void">void</FONT> run() {
<A NAME="49"></A>        System.out.println(<FONT ID="StringLiteral">"Welcome to jjsched console. Type 'help' for standard command help."</FONT>);
<A NAME="50"></A>
<A NAME="51"></A>        <FONT ID="While">while</FONT> (doContinue) {
<A NAME="52"></A>            String line = <FONT ID="StringLiteral">""</FONT>;
<A NAME="53"></A>            <FONT ID="Try">try</FONT> {
<A NAME="54"></A>                line = reader.readLine();
<A NAME="55"></A>            } <FONT ID="Catch">catch</FONT> (Exception e) {
<A NAME="56"></A>                <FONT ID="Continue">continue</FONT>;
<A NAME="57"></A>            }
<A NAME="58"></A>
<A NAME="59"></A>            LinkedList&lt;String&gt; tokens = StringParser.parseLine(line);
<A NAME="60"></A>
<A NAME="61"></A>            <FONT ID="SingleLineComment">//Macro expansion
<A NAME="62"></A></FONT>            ListIterator it = tokens.listIterator(<FONT ID="IntegerLiteral">0</FONT>);
<A NAME="63"></A>            <FONT ID="While">while</FONT> (it.hasNext()){
<A NAME="64"></A>                String token = (String)it.next();
<A NAME="65"></A>                <FONT ID="If">if</FONT> (theMacros.isMacro(token)){
<A NAME="66"></A>                    it.remove();
<A NAME="67"></A>                    Iterator macroit = theMacros.getMacroBody(token).iterator();
<A NAME="68"></A>                    <FONT ID="While">while</FONT> (macroit.hasNext()){
<A NAME="69"></A>                        it.add((String)macroit.next());
<A NAME="70"></A>                    }
<A NAME="71"></A>                }
<A NAME="72"></A>            }
<A NAME="73"></A>
<A NAME="74"></A>            <A HREF="../../czestmyr/jjsched/Action.java.html">Action</A> action = theParser.parse(tokens, <FONT ID="StringLiteral">"console"</FONT>, <FONT ID="StringLiteral">"console"</FONT>);
<A NAME="75"></A>            theExecutor.execute(action);
<A NAME="76"></A>
<A NAME="77"></A>        }
<A NAME="78"></A>    }
<A NAME="79"></A>
<A NAME="80"></A>    <FONT ID="FormalComment">/**
<A NAME="81"></A>     * Stops the console
<A NAME="82"></A>     */</FONT>
<A NAME="83"></A>    <FONT ID="Public">public</FONT> <FONT ID="Void">void</FONT> discontinue() {
<A NAME="84"></A>        doContinue = <FONT ID="False">false</FONT>;
<A NAME="85"></A>        <FONT ID="This">this</FONT>.interrupt();
<A NAME="86"></A>    }
<A NAME="87"></A>
<A NAME="88"></A>    <FONT ID="Private">private</FONT> <A HREF="../../czestmyr/jjsched/ActionExecutor.java.html">ActionExecutor</A> theExecutor;
<A NAME="89"></A>    <FONT ID="Private">private</FONT> <A HREF="../../czestmyr/jjsched/CommandParser.java.html">CommandParser</A> theParser;
<A NAME="90"></A>    <FONT ID="Private">private</FONT> <A HREF="../../czestmyr/jjsched/Macros.java.html">Macros</A> theMacros;
<A NAME="91"></A>
<A NAME="92"></A>    <FONT ID="Private">private</FONT> <FONT ID="Boolean">boolean</FONT> doContinue;
<A NAME="93"></A>
<A NAME="94"></A>    <FONT ID="Private">private</FONT> BufferedReader reader;
<A NAME="95"></A>}
<A NAME="96"></A>
<A NAME="97"></A></pre>
</BODY>
</HTML>